package com.opencloud.iot.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.opencloud.common.model.PageParams;
import com.opencloud.iot.client.model.entity.IotTask;
import com.opencloud.iot.client.model.entity.IotTaskRun;
import com.opencloud.iot.provider.mapper.IotTaskMapper;
import com.opencloud.iot.provider.mapper.IotTaskRunMapper;
import com.opencloud.iot.provider.service.IotTaskRunService;
import com.opencloud.iot.provider.service.IotTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 进出记录操作
 * @author yeyong
 */

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class IotTaskRunServiceImpl implements IotTaskRunService {

    @Autowired
    private IotTaskRunMapper iotTaskRunMapper;

    @Override
    public IPage<IotTaskRun> findListPage(PageParams pageParams) {
        QueryWrapper<IotTaskRun> queryWrapper = new QueryWrapper();
        queryWrapper.lambda();
        return iotTaskRunMapper.selectPage(new Page(pageParams.getPage(),pageParams.getLimit()),queryWrapper);
    }

    @Override
    public IotTaskRun findTaskRunByKey(String key) {
        QueryWrapper<IotTaskRun> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().eq(ObjectUtils.isNotEmpty(key),IotTaskRun::getTaskid,key)
                .orderByDesc(IotTaskRun::getCreatetime);
        return iotTaskRunMapper.selectOne(queryWrapper);
    }
    
    @Override
    public Integer AddTaskRun(IotTaskRun entiy)
    {
        return iotTaskRunMapper.insert(entiy);
    }

    @Override
    public Integer UpdateTaskRun(IotTaskRun entiy)
    {
        return iotTaskRunMapper.updateById(entiy);
    }

}
